package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Arrays;

@Slf4j
// url:网址
// 给我的类起一个网址路径
@RequestMapping("first")
@Controller
public class FirstController {
    //http://localhost:8001/first/a
    @RequestMapping("/a")
    public String a() {
        log.info("用户访问了FirstController的a方法");
        // 默认情况下，这个是返回的页面名称
        return "index";// /index.html
    }
    //http://localhost:8001/first/b
    @RequestMapping("/b")
    public String b() {
        log.info("用户访问了FirstController的b方法");
        return "index";
    }
    //http://localhost:8001/first/c
    // 传递一个参数 name就是参数名
    @RequestMapping("/c")
    public String c(@RequestParam("name")String name) {
        log.info("用户访问了FirstController的c方法",name);
        return "index";
    }

    @RequestMapping("/d")
    public String d(@RequestParam("name")String name,@RequestParam("age")int age,@RequestParam("loves")String[] loves) {
        log.info("用户访问了FirstController的b方法,接受参数为：{},{},{}",name,age, Arrays.toString(loves));
        return "index";
    }
    @RequestMapping("/e")
    public String e(User user) {
        log.info("用户访问了FirstController的c方法,接受参数为：{}",user);
        return "index";
    }
    @RequestMapping("/f")
    public String f() {
        return "redirect:/index.html";
    }
}
